package com.lscl.rabbitmq.listener;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * Consumer 限流机制
 *  perfetch = 1,表示消费端每次从mq拉去一条消息来消费，直到手动确认消费完毕后，才会继续拉去下一条消息。
 */

@Component
public class QosListener {

    @RabbitListener(queues = "test_queue_confirm")
    public void test_queue_confirm(Message message){

        try {
            Thread.sleep(1000);
            //1.获取消息
            System.out.println(new String(message.getBody()));

            //2. 处理业务逻辑
            System.out.println("处理业务逻辑...");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

